package mornd.custom;

import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletRegistrationBean;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;

/**
 * @author: mornd
 * @dateTime: 2023/5/9 - 16:30
 */

@Configuration
@ComponentScan
public class WebConfig {

    /**
     * 注册内嵌 web 服务器
     * @return
     */
    @Bean
    public TomcatServletWebServerFactory webServerFactory() {
        return new TomcatServletWebServerFactory();
    }

    @Bean
    public DispatcherServlet dispatcherServlet() {
        return new DispatcherServlet();
    }

    @Bean
    public DispatcherServletRegistrationBean registrationBean(DispatcherServlet dispatcherServlet) {
        DispatcherServletRegistrationBean dispatcherServletRegistrationBean = new DispatcherServletRegistrationBean(dispatcherServlet, "/");
        //dispatcherServletRegistrationBean.setLoadOnStartup(1);
        return dispatcherServletRegistrationBean;
    }

    @Bean
    public MyHandlerMapping handlerMapping() {
        return new MyHandlerMapping();
    }

    @Bean
    public MyHandlerAdapter handlerAdapter() {
        return new MyHandlerAdapter();
    }
}
